from typing import Any

from sqlalchemy import select, insert

from recruit.adapter.database.gateway.base import SQLAlchemyGateway
from recruit.adapter.database.models import Resume
from recruit.adapter.stubs import StubResumeGateway
from recruit.domain.models.resume_id import ResumeId


class ResumeGateway(SQLAlchemyGateway, StubResumeGateway):
    async def create(self, **kwargs: Any) -> Resume:
        stmt = insert(Resume).values(**kwargs).returning(Resume)
        result = await self.session.execute(stmt)
        return result.scalar_one()

    async def get_one(self, **kwargs: Any) -> Resume | None:
        stmt = select(Resume).filter_by(**kwargs)
        result = await self.session.execute(stmt)
        return result.scalar_one_or_none()

    async def check_resume(self, id: ResumeId) -> bool:
        stmt = select(Resume).where(Resume.id == id).exists()
        return await self.session.scalar(select(stmt))
